<template>
  <div class="container">
    <div class="recom_banner" :style="{background: mainColor}">
      <p class="recom_val">{{totalPrice}}</p>
      <p class="recom_name">推荐奖励（元）</p>
    </div>
    <userList :list="recordList"></userList>
    <load-more @loadMore="loadMore"></load-more>
  </div>
</template>

<script>
import userList from "./component/user-list.vue";
import { getRecordedList } from "@/api/vip";
import loadMore from "@/components/load-more";
import { mapState } from "vuex";
export default {
  data() {
    return {
      recordList: [],
      totalPrice:0,
      page: 1,
      isAll: false,
      loading: false
    };
  },
  components: {
    userList,
    loadMore
  },
  computed: {
    ...mapState({
      mainColor: state => state.app.mainColor,
      subColor: state => state.app.subColor
    })
  },
  methods: {
    getRecordedList(page) {
      getRecordedList({ page, type: 2 }).then(res => {
        if (res.status === 200) {
          this.totalPrice = res.data.data.bonus;
          this.recordList.push(...res.data.data.info);
          if (res.data.data.info.length === 0) {
            this.isAll = true;
            this.$dialog.toast({
              mes: "没有更多了",
              timeout: 1000
            });
          }
        }
        this.loading = false;
      });
    },
    loadMore() {
      if (this.loading || this.isAll || this.recordList.length === 0)
        return;
      this.loading = true;
      this.getRecordedList(++this.page);
    }
  },
  created() {
    this.getRecordedList(1);
  }
};
</script>

<style lang="less" scoped>
.container {
  min-height: 100%;
  height: auto;
  .clear {
    clear: both;
  }

  .recom_banner {
    background: #0678ff;
    width: 100%;
    padding-top: 1.4rem;
    height: 4.6rem;
    text-align: center;

    .recom_val {
      font-weight: bold;
      font-size: 0.96rem;
      margin-bottom: 0.2rem;
      color: #ffffff;
    }
    .recom_name {
      font-size: 0.56rem;
      color: #ffffff;
    }
  }
}
</style>